package com.rfid.assistant.activity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.rfid.socketio.SocketIoInstance;

public class RemoteSRActivity extends SRBaseActivity{

    public static void startActivity(Context context) {
        Intent intent = new Intent();
        intent.setClass(context,RemoteSRActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable  Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!SocketIoInstance.INSTANCE.isConnect()) {
            Toast.makeText(this,"服务器连接失败",Toast.LENGTH_SHORT).show();
            finish();
        }
        SocketIoInstance.INSTANCE.setOnReceiveListener(this);
    }

    @Override
    public void send(View view) {
        String text = mEditText.getText().toString();
        if (!TextUtils.isEmpty(text)) {
            SocketIoInstance.INSTANCE.getClient().send(text);
            mMessages.add(0,"发送：" + text);
            mAdapter.notifyDataSetChanged();
        }
    }

    @Override
    protected void requestFile(String path) {
        SocketIoInstance.INSTANCE.getClient().sendReqFileCmd(path);
    }

    @Override
    protected void requestDir(String path) {
        SocketIoInstance.INSTANCE.getClient().sendQueryFileListCmd(path);
    }

    @Override
    protected void handleSelectedFile(Uri uri) {
        super.handleSelectedFile(uri);
        SocketIoInstance.INSTANCE.getClient().sendFile(this,uri);
    }

    @Override
    protected void deleteRemoteFile(String path) {
        SocketIoInstance.INSTANCE.getClient().sendDeleteFile(path);
    }
}
